package com.xk857.aliyun;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.teaopenapi.models.Config;
import com.xk857.properties.AliyunProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 阿里云相关产品对象Bean注入
 *
 * @author cv大魔王
 * @version 1.0
 * @date 2021/7/24 22:52
 */
@Component
public class AliBaseBean {


    @Autowired
    private AliyunProperties aliyunProperties;

    @Bean
    public Client createClient() throws Exception {
        Config config = new Config()
                .setAccessKeyId(aliyunProperties.getAccessKeyId())
                .setAccessKeySecret(aliyunProperties.getAccessKeySecret());
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new Client(config);
    }


    @Bean
    public OSS getOssClient(){
        OSS oss = new OSSClientBuilder().build(aliyunProperties.getEndpoint(), aliyunProperties.getAccessKeyId(), aliyunProperties.getAccessKeySecret());
        return oss;
    }

}
